#include <bits/stdc++.h>

using namespace std;

const int N = 502;
const int M = 1e5 + 2;
int n, x;
long long ans, happy;
int cost[N];
long long val[N], dp[M];

int main()
{
    cin >> n >> x;
    int pos = 1;
    for (int i = 1, pre, cur, well; i <= n; i++)
    {
        scanf("%d%d%lld", &pre, &cur, &happy);
        well = pre - cur - cur;
        if (well >= 0)
        {
            ans += happy;
            x += well;
        }
        else
        {
            cost[pos] = -well;
            val[pos++] = happy;
        }
    }

    for (int i = 1; i <= pos; i++)
    {
        for (int j = x; j >= cost[i]; j--)
        {
            dp[j] = max(dp[j], dp[j - cost[i]] + val[i]);
        }
    }
    ans += dp[x];
    cout << ans << endl;
    return 0;
}